package p2pmodule;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Class that represents a peer in the p2p network.
 * 
 * @author ole
 */
public class Peer {
	// Class attributes.
	private InetAddress addr = null;
	private int port = -1;
	
	/**
	 * Class constructor.
	 * @param address:
	 * 		Either the name of the peer or the dotted decimal IP
	 * 		representation.
	 * @param port:
	 * 		The port where the peer is listening.
	 * @throws UnknownHostException:
	 * 		Raised if cannot transform addr into an IP address.
	 */
	public Peer(String addr, int port) throws UnknownHostException {
		this.addr = InetAddress.getByName(addr);
		this.port = port;
	}
	
	/**
	 * Returns the InetAddress of this Peer.
	 */
	public InetAddress getAddr() {
		return addr;
	}
	
	/**
	 * Returns the port where the Peer is listening.
	 */
	public int getPort() {
		return port;
	}
}
